﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ExamSelect : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["studIdcard"] != null)
        {
            if (!Page.IsPostBack)
            {
                bindDTable();
            }
        }
    }
    private void bindDTable()
    {
        DataTable dt = Exam.ExamTime_GetCurrExamList();
        gv.DataSource = dt;
        gv.DataBind();
    }

    protected override void Page_LoadOnce()
    {

    }


    protected void goApply_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string gradeLimite = gv.DataKeys[e.Row.RowIndex].Values[3].ToString().Trim();
            string timeID = gv.DataKeys[e.Row.RowIndex].Values[4].ToString().Trim();
            DataTable dt = Exam.getEmTimeByEmId(timeID);
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                HyperLink hlGoApply = (HyperLink)e.Row.FindControl("goApply");
                Label lbTips = (Label)e.Row.FindControl("lbTips");
                //年级限制
                DataTable dt_stud = User_Control.getStudInfoByIdCard(IDCard);
                if (dt_stud.Rows.Count > 0 )
                {
                    string grade = dt_stud.Rows[0]["StudYear"].ToString().Trim();

                    if (grade != string.Empty && Exam.ExamTimeIsPermit(timeID, SchoolFlag) && ( gradeLimite.Trim() == string.Empty ||  gradeLimite.Contains(grade) || Exam.ExamTimeIsPermit(timeID, IDCard)) )
                    {
                        //加密
                        hlGoApply.NavigateUrl = BSUtility.mainUrl + "BM/StudInfoConfirm.aspx?TimeID=" + timeID;
                        DateTime applyBeginTime = DateTime.Parse(dr["ApplyBeginTime"].ToString());
                        if (applyBeginTime > DateTime.Now)
                        {
                            hlGoApply.Visible = false;
                        }
                    }
                    else
                    {
                        hlGoApply.Visible = false;
                        lbTips.Visible = true;
                        lbTips.Text = "您不在允许报名范围内";
                    }
                }
            }
        }
        
    }
}